"use strict";
cc._RF.push(module, '5b401W+tqhL9pPe+46kG0Kz', 'LevelUI');
// scripts/LevelUI.ts

Object.defineProperty(exports, "__esModule", { value: true });
var Model_1 = require("./Model");
var Config_1 = require("./Config");
var LevelItem_1 = require("./LevelItem");
var WxUtil_1 = require("./WxUtil");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var LevelUI = /** @class */ (function (_super) {
    __extends(LevelUI, _super);
    function LevelUI() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.content = null;
        _this.ItemPrefab = null;
        _this.TopPrefab = null;
        _this.LevelItemFnt = null;
        return _this;
    }
    LevelUI.prototype.onLoad = function () {
        Config_1.default.init();
        console.log('LevelUI');
        var top = cc.instantiate(this.TopPrefab);
        this.node.addChild(top);
        top.getChildByName('level_txt').active = false;
        this.content.removeAllChildren(true);
        WxUtil_1.default.showBanner();
        for (var i = 0; i < Config_1.default.drawLevels.length - 1; i++) {
            var item = cc.instantiate(this.ItemPrefab);
            item.x = i % 4 * 160 - 240;
            item.y = -68 - Math.floor(i / 4) * 160;
            this.content.addChild(item);
            item.getComponent(LevelItem_1.default).level = i + 1;
            if (i + 1 <= Model_1.default.game.drawLevel) {
                item.getChildByName('star1').active = Model_1.default.game.drawLevelInfo[i] >= 1;
                item.getChildByName('star2').active = Model_1.default.game.drawLevelInfo[i] >= 2;
                item.getChildByName('star3').active = Model_1.default.game.drawLevelInfo[i] == 3;
            }
            else {
                item.getChildByName('btn_lock').active = true;
                item.getChildByName('btn').active = false;
                item.getChildByName('star1').active = false;
                item.getChildByName('star2').active = false;
                item.getChildByName('star3').active = false;
            }
            item.getChildByName('btn').on(cc.Node.EventType.TOUCH_END, this.itemClick, this);
        }
        for (var i = 0; i < Config_1.default.drawLevels.length - 1; i++) {
            if (i + 1 <= Model_1.default.game.drawLevel) {
                var fnt = cc.instantiate(this.LevelItemFnt);
                fnt.x = i % 4 * 160 - 240;
                fnt.y = -38 - Math.floor(i / 4) * 160;
                this.content.addChild(fnt);
                fnt.getComponent(cc.Label).string = (i + 1) + '';
            }
        }
    };
    LevelUI.prototype.itemClick = function (event) {
        var level = event.target.parent.getComponent(LevelItem_1.default).level;
        Model_1.default.game.selectedLevel = level;
        cc.director.loadScene('gameDraw');
    };
    LevelUI.prototype.onDestroy = function () {
        WxUtil_1.default.destroyBanner();
    };
    __decorate([
        property(cc.Node)
    ], LevelUI.prototype, "content", void 0);
    __decorate([
        property(cc.Prefab)
    ], LevelUI.prototype, "ItemPrefab", void 0);
    __decorate([
        property(cc.Prefab)
    ], LevelUI.prototype, "TopPrefab", void 0);
    __decorate([
        property(cc.Prefab)
    ], LevelUI.prototype, "LevelItemFnt", void 0);
    LevelUI = __decorate([
        ccclass
    ], LevelUI);
    return LevelUI;
}(cc.Component));
exports.default = LevelUI;

cc._RF.pop();